package jee.boot.module.bpm.validation;

import jee.boot.common.basic.ServiceException;
import jee.boot.common.basic.result.MapData;
import jee.boot.common.utils.DateUtils;

import java.text.ParseException;

/**
 * 日期校验
 */
public class DateValidation extends BasicValidation implements DataValidation {
    private String pattern = "yyyy-MM-dd";

    /**
     * 数据校验
     *
     * @param value
     * @param params
     */
    @Override
    public void validation(Object value, Object... params) {
        if (value == null) {
            return;
        }
        try {
            DateUtils.parseDate(value.toString(), pattern);
        } catch (ParseException e) {
            logger.error(e.getMessage(), e);
            throw new ServiceException(1431, MapData.instance().put("param", getParam(0, "", params)).data());
        }
    }
}
